package com.bdqn.service.impl;

import com.bdqn.entity.Supplier;
import com.bdqn.mapper.SupplierMapper;
import com.bdqn.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("supplierService")
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;

    @Override
    public List<Supplier> findAll(Supplier supplier) {
        return supplierMapper.selectAllSuppliers(supplier);
    }

    @Override
    @Transactional
    public int saveBatch(List<Supplier> SupplierList) {
        int rows = 0;
        for (int i = 0; i < SupplierList.size(); i++) {
            // 拿出每一条用户数据插入
            Supplier supplier = SupplierList.get(i);
            // 调用插入数据操作，计入总受影响行数
            rows += supplierMapper.insert(supplier);
        }
        // 返回总受影响行数
        return rows;
    }

    @Override
    @Transactional
    public int updateBatch(List<Supplier> SupplierList) {
        int rows = 0;
        for (int i = 0; i < SupplierList.size(); i++) {
            // 拿出每一条用户数据插入
            Supplier supplier = SupplierList.get(i);
            // 调用插入数据操作，计入总受影响行数
            rows += supplierMapper.update(supplier);
        }
        // 返回总受影响行数
        return rows;
    }

    @Override
    @Transactional
    public int deleteBatch(List<Long> idList) {
        int rows = 0;
        for (int i = 0; i < idList.size(); i++) {
            // 拿出每一条用户数据插入
            Long id = idList.get(i);
            // 调用插入数据操作，计入总受影响行数
            rows += supplierMapper.delete(id);
        }
        // 返回总受影响行数
        return rows;
    }

    public void setSupplierMapper(SupplierMapper supplierMapper) {
        this.supplierMapper = supplierMapper;
    }
}
